package com.ns.dcjh.listener;

import com.alibaba.fastjson.JSONObject;
import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.ns.dcjh.utils.BlockUtils;


public class MyBDAbstractLocationListener extends BDAbstractLocationListener {
    private BlockUtils onReceive;

    @Override
    public void onReceiveLocation(BDLocation bdLocation) {
        if (bdLocation.getLocType() != BDLocation.TypeServerError) {
            if (onReceive == null)      return;
            JSONObject data = new JSONObject();
            data.put("longitude", bdLocation.getLongitude());
            data.put("latitude", bdLocation.getLatitude());
            data.put("accuracy", 0);
            data.put("adCode", bdLocation.getAdCode());
            data.put("province", bdLocation.getProvince());
            data.put("city", bdLocation.getCity());
            data.put("district", bdLocation.getDistrict());
            //data.put("data", bdLocation);

            onReceive.callbackWithJSONObject(data);
        }
    }

    @Override
    public void onLocDiagnosticMessage(int i, int i1, String s) {
        super.onLocDiagnosticMessage(i, i1, s);
    }

    public BlockUtils getOnReceive() {
        return onReceive;
    }

    public void setOnReceive(BlockUtils onReceive) {
        this.onReceive = onReceive;
    }
}
